<template>
  <div style="padding:0.3rem 0.6rem">
    <div class="IntelligentClassification">
      <div class="yx-content">
        <table class="yx-table yx-widthP100 manager-table">
          <tr>
            <th>工号</th>
            <th>姓名</th>
            <th>角色</th>
            <th>状态</th>
            <th>操作</th>
          </tr>
          <tr v-for="item in managerViewData.items">
            <td>{{item.EMPLOYEE_NUMBER}}</td>
            <td>{{item.USERNAME}}</td>
            <td>
              <span v-show="item.role_id==1">管理员</span>
              <span v-show="item.role_id==2">采购员</span>
              <span v-show="item.role_id==3">sourcing</span>
              <span v-show="item.role_id==4">计划员</span>
              <span v-show="item.role_id==5">计划管理员</span>
              <span v-show="item.role_id==6">采购管理员</span>
            </td>
            <td><span v-show="item.status==1">激活</span><span v-show="item.status==0">冻结</span></td>
            <td>
              <input type="button" class="manager_button manager_button_active" value="激活" @click="managerActiveFun(item.EMPLOYEE_NUMBER)">
              &nbsp;&nbsp;
              <input type="button" class="manager_button manager_button_freeze" value="冻结" @click="managerFreezeFun(item.EMPLOYEE_NUMBER)">
              &nbsp;&nbsp;
              <input type="button" class="manager_button manager_button_resetPasswd" value="重置密码" @click="managerResetPwdFun(item.EMPLOYEE_NUMBER)">
            </td>
          </tr>
        </table>
        <div class="table-tr" v-if="managerViewData.pages>1&&!managerViewING&&!managerViewERROR">
          <div class="pageturn">
            共
            <em>{{managerViewData.total | numberThousand}}</em>
            条，第
            <em>{{managerViewData.page | numberThousand}}</em>
            /
            <em>{{managerViewData.pages | numberThousand}}</em>
            页，跳转到第
            <input type="text" class="pageturn-ipt" v-model="iptPage" value=""/>
            页
            <span class="page-turn" v-on:click="managerViewFun(iptPage)">跳转</span>
            <span class="page-first" v-on:click="managerViewFun(1)">首页</span>
            <span class="page-up"
                  v-on:click="managerViewData.page>1?managerViewFun(managerViewData.page-1):''">上一页</span>
            <span class="page-down"
                  v-on:click="managerViewData.page<managerViewData.pages?managerViewFun(managerViewData.page+1):''">下一页</span>
            <span class="page-last"
                  v-on:click="managerViewFun(managerViewData.pages)">末页</span>
          </div>
        </div>
        <div class="loadingBox manager_loadingBox">
          <div class="loadding80" v-show="managerViewING"></div>
          <div class="frame-noData" v-show="managerViewERROR">暂无数据...</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import calender from '../common/js/calenderMonth';
  import common from '../common/js/common';

  export default {
    watch: {},
    mounted() {
      common.rem();
      this.managerViewFun(1);
    },
    data() {
      return {
        managerViewING:true,
        managerViewERROR:false,
        managerViewData:{},
        iptPage:'',
      }
    },
    methods:{
      managerViewFun:function(page){
        var _self=this;
        var yx_data={
          page:page
        };
        _self.managerViewING=true;
        common.getData(0,common.url_constitute.manager_view, 'post', yx_data,function(d){
          _self.managerViewING=false;
          if(d.data.code==1024){
            _self.managerViewERROR=false;
            _self.managerViewData=d.data.user_list;
            _self.iptPage=_self.managerViewData.page;
          }else if(d.data.code==9007){
            _self.managerViewERROR=true;
          }
        })
      },
      managerFreezeFun:function(name){
        var _self=this;
        var yx_data={
          "employee_number": name
        };
       /* _self.managerActiveING=true;*/
        common.getData(-1,common.url_constitute.manager_freeze,'post',yx_data,function(d){
         /* _self.managerActiveING=false;*/
          if(d.data.code==1024){
            alert(d.data.message);
           /* _self.managerViewData.items[index].status=0;*/
            _self.managerViewData=d.data.user_list;
          /*  _self.managerActiveERROR=false;*/
          }else{
           /* _self.managerActiveERROR=true;*/
           alert(d.data.message)
          }
        })
      },
      managerActiveFun:function(name){
        var _self=this;
        var yx_data={
          "employee_number": name
        };
        /* _self.managerActiveING=true;*/
        common.getData(-1,common.url_constitute.manager_active,'post',yx_data,function(d){
          /* _self.managerActiveING=false;*/
          if(d.data.code==1024){
            alert(d.data.message);
            /*_self.managerViewData.items[index].status=1;*/
            _self.managerViewData=d.data.user_list;
            /*  _self.managerActiveERROR=false;*/
          }else{
            /* _self.managerActiveERROR=true;*/
            alert(d.data.message)
          }
        })
      },
      managerResetPwdFun:function(name){
        var _self=this;
        var yx_data={
          "employee_number": name
        };
        common.getData(-1,common.url_constitute.reset_password,'post',yx_data,function(d){
          if(d.data.code==1024){
            alert(d.data.message);
          }else{
            alert(d.data.message)
          }
        })
      }
    }
  }

</script>

<style>
  @import "../common/css/base.css";
  @import "../common/css/yx.less";
</style>
